package com.example.g32.park

import com.example.base.http.ApiServer
import com.example.base.mvi.BaseViewModel
import com.example.base.mvi.RequestType
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class ParkViewModel @Inject constructor(val apiServer: ApiServer): BaseViewModel<ParkIntent>() {
    override fun handlerIntent(it: ParkIntent) {
//        when(it){
//            is ParkIntent.getParkByType->{
//                pagingReq({ParkDataSource(apiServer,it.type,"类型")})
//            }
//            is ParkIntent.getParkByArea->{
//                pagingReq({ParkDataSource(apiServer,it.area,"区域")})
//            }
//            is ParkIntent.getParkByStatus->{
//                pagingReq({ParkDataSource(apiServer,it.status,"状态")})
//            }
//            is ParkIntent.getParkByCarNo->{
//                pagingReq({ParkDataSource(apiServer,it.carNo,"车牌号")})
//            }
//            is ParkIntent.deletePark->{
//                httpRequest(apiServer.deletePark(it.id), RequestType.DELETE)
//            }
//
//            is ParkIntent.queryById->{
//                pagingReq({ParkDataSource(apiServer, it.userId.toString(), "Id查找")})
//            }
//        }
        when(it){
            is ParkIntent.getParkByType->{
//                pagingRequest({ParkDataSource(apiService,it.type,"类型")})
                httpRequest(apiServer.getParkByType(it.type))
            }
            is ParkIntent.getParkByArea->{
//                pagingRequest({ParkDataSource(apiService,it.area,"区域")})
                httpRequest(apiServer.getParkByArea(it.area.toInt()))
            }
            is ParkIntent.getParkByStatus->{
//                pagingRequest({ParkDataSource(apiService,it.status,"状态")})
                httpRequest(apiServer.getParkByStatus(it.status))
            }
            is ParkIntent.getParkByCarNo->{
//                pagingRequest({ParkDataSource(apiService,it.carNo,"车牌号")})
                httpRequest(apiServer.getParkByCarNo(it.carNo),RequestType.PARKITEM)
            }
            is ParkIntent.deletePark->{
                httpRequest(apiServer.deletePark(it.id),RequestType.DELETE)
            }
            is ParkIntent.addPark->{
                httpRequest(apiServer.addPark(toBody(it.bean)))
            }
            is ParkIntent.getParkById->{
                httpRequest(apiServer.getParkById(it.id))
            }
            is ParkIntent.updatePark->{
                httpRequest(apiServer.updatePark(it.id,toBody(it.bean)),RequestType.UPDATE)
            }

            else -> {}
        }
    }
}